package com.ctgu.springboot.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.common.Result;
import com.ctgu.springboot.entity.ScInfo;
import com.ctgu.springboot.service.ScInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@RestController
@RequestMapping("/school")
public class ScInfoController {

    @Autowired
    private ScInfoService scInfoService;

    //新增学校
    @PostMapping("save")
    public Result save(@RequestBody ScInfo scInfo){
        return scInfoService.save(scInfo)?Result.suc():Result.fail();
    }

    //修改学校信息
    @PostMapping("update")
    public Result update(@RequestBody ScInfo scInfo){
        return scInfoService.updateById(scInfo)?Result.suc():Result.fail();
    }

    //删除学校信息
    @GetMapping("del")
    public Result del(@RequestParam Integer sc_id){
        return scInfoService.removeById(sc_id)?Result.suc():Result.fail();
    }

    //分页查询学校信息
    @PostMapping("/listPage")
    public Result listPage(@RequestBody QueryPageParam query) {
        IPage<ScInfo> result = scInfoService.schoolPage(query);
        return Result.suc(result.getRecords(), result.getTotal());
    }

    //
    //@GetMapping("getList")
    //public List<ScInfo> getList(){
    //    return scInfoService.getList();
    //}


    //查询所有学校信息（不分页）
    @GetMapping("list")
    public List<ScInfo> list(){
        return scInfoService.list();
    }
}
